<?php
declare(strict_types=1);
namespace app\admin\controller;
use app\facade\Basic;
use app\admin\service\MinerVideo as ServiceMinerVideo;
use think\Request;

/**
 *  矿机视频管理
 */
class MinerVideo extends BaseController
{

    /**
     *   获取枚举
     */
    public function resource(Request $request)
    {
        $param['field'] = $request->param('field');
        $serviceMinerVideo = new ServiceMinerVideo();
        $result = $serviceMinerVideo->getEnum($param);
        return Basic::json($result);
    }

    /**
     *  供应商/零售商
     */
    public function getList(Request $request)
    {
        $param['pageIndex'] = $request->param('pageIndex',1);
        $param['pageSize'] = $request->param('pageSize',50);
        $param['video_title'] = $request->param('video_title',null);
        $param['creator'] = $request->param('creator',null);
        $param['start_date'] = $request->param('start_date',null);
        $param['end_date'] = $request->param('end_date',null);
        $param['model_id'] = $request->param('model',null);

        /* 验证 */
        $this->validateData($param,'MinerVideo.getList');

        $serviceMinerVideo = new ServiceMinerVideo();
        $result = $serviceMinerVideo->getList($param);
        return Basic::json($result);
    }


    /**
     *  状态修改
    */
    public function status(Request $request)
    {
        $param['creator'] = $request->operator_id;
        $param['id'] = $request->param('id',null);
        $param['showstate'] = $request->param('showstate',null);

        /* 验证 */
        $this->validateData($param,'MinerVideo.status');

        $serviceMinerVideo = new ServiceMinerVideo();
        $result = $serviceMinerVideo->status($param);
        return Basic::json($result);
    }


    /**
     *  添加机型
    */
    public function save(Request $request)
    {
        $param['creator'] = $request->operator_id;

        $param['model_id'] = $request->param('model_id',null);
        $param['video_title'] = $request->param('video_title',null);
        $param['youtube_vid'] = $request->param('youtube_vid',null);
        $param['coverimage_id'] = $request->param('coverimage_id',null);
        $param['init_shownumber'] = $request->param('init_shownumber',null);
        $param['pm_ids'] = $request->param('pm_ids',null);
        $param['blogger_name'] = $request->param('blogger_name',null);
        $param['publish_time'] = $request->param('publish_time',null);
        $param['category'] = $request->param('category',null);
        $param['video_id'] = $request->param('video_id',null);
        $param['showstate'] = $request->param('showstate',null);
        $param['sort'] = $request->param('sort',100);
        $param['pmv_id'] = $request->param('pmv_id',[]);
        $param['smv_id'] = $request->param('smv_id',[]);

        if ( !empty($param['video_title']) ) {
            $param['video_title'] = trim($param['video_title']);
        }


        /* 验证 */
        $this->validateData($param,'MinerVideo.save');

        $serviceMinerVideo = new ServiceMinerVideo();
        $result = $serviceMinerVideo->save($param);
        return Basic::json($result);
    }


    /**
     *  获取详情
    */
    public function detail(Request $request)
    {
        $param['operator_id'] = $request->operator_id;
        $param['id'] = $request->param('id',null);

        /* 验证 */
        $this->validateData($param,'Seller.detail');

        $serviceMinerVideo = new ServiceMinerVideo();
        $result = $serviceMinerVideo->detail($param);
        return Basic::json($result);
    }

    /**
     *  修改机型
    */
    public function update(Request $request)
    {
        $param['creator'] = $request->operator_id;

        $param['id'] = $request->param('id',null);
        $param['model_id'] = $request->param('model_id',null);
        $param['video_title'] = $request->param('video_title',null);
        $param['youtube_vid'] = $request->param('youtube_vid',null);
        $param['coverimage_id'] = $request->param('coverimage_id',null);
        $param['init_shownumber'] = $request->param('init_shownumber',null);
        $param['pm_ids'] = $request->param('pm_ids',null);
        $param['blogger_name'] = $request->param('blogger_name',null);
        $param['publish_time'] = $request->param('publish_time',null);
        $param['category'] = $request->param('category',null);
        $param['video_id'] = $request->param('video_id',null);
        $param['showstate'] = $request->param('showstate',null);
        $param['sort'] = $request->param('sort',100);
        $param['pmv_id'] = $request->param('pmv_id',[]);
        $param['smv_id'] = $request->param('smv_id',[]);
        
        if ( !empty($param['video_title']) ) {
            $param['video_title'] = trim($param['video_title']);
        }

       $this->validateData($param,'MinerVideo.update');

        $serviceMinerVideo = new ServiceMinerVideo();
        $result = $serviceMinerVideo->update($param);
        return Basic::json($result);
   }

    /**
     *  删除机型
    */
    public function delete(Request $request)
    {
        $param['updater'] = $request->operator_id;
        $param['ids'] = $request->param('ids',null);

        /* 验证 */
        $this->validateData($param,'MinerVideo.delete');

        $serviceMinerVideo = new ServiceMinerVideo();
        $result = $serviceMinerVideo->delete($param);
        return Basic::json($result);
    }



}
